﻿using System;
using System.Collections.Generic;
using System.Text;
using IBLL;
using Common.Logging;
using AppToolKit.Core.Context.Spring;
using Utility;
using BLL.Action.Core.Caching;

namespace BLL.Action.Core.Base
{
    [AutoWiring]
    public class ActionFactory:IActionFactory
    {
        public ActionFactory()
        {

        }
        private const string Prefix = "Action";
        ILog log = LogManager.GetLogger(LogDefault.AppInfo);
        [AutoWiring]
        public ClientCache CacheHolder { get; set; }

        [AutoWiring]
        public ContextAware ContextAwareHolder { get; set; }

        public  IAction CreateAction(string action)
        {
            //return CacheHelper.Cache(CacheHolder, string.Format("{0}_{1}",Prefix, action), delegate { return Create(action); }) as IAction;
            return Create(action); 
        }


        private IAction Create(string action)
        {
            log.Debug("new action");
            Type type = Type.GetType(action);
            IAction Instance=Activator.CreateInstance(type) as IAction;
            ContextAwareHolder.AutowireObject(Instance);
            return Instance;
        }
    }
}
